import java.util.Scanner;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/7 9:14
 * @Copyright 博为峰
 */
public class StuTest02 {
    public static void login(Scanner scanner) {
        do {
            System.out.println("请输入用户名");
            String name = scanner.nextLine();
            System.out.println("请输入密码");
            String password = scanner.nextLine();
            if (name.equals("zhangsan") && password.equals("123")) {
                System.out.println("欢迎使用XXX系统");
                break;
            }
        } while (true);
    }

    public static void addStu(Scanner scanner, String[][] stus, int index) {
        System.out.println("请输入用户名");
        String stuName = scanner.nextLine();
        System.out.println("请输入年龄");
        String stuAge = scanner.nextLine();
        String[] stu = {stuName, stuAge};
        stus[index] = stu;
        index++;
    }

    //对于条件固定且相对少的时候，使用switch可以提高效率
    public static void main(String[] args) {
        String[][] stus = new String[100][2];
        int index = 0;
        System.out.println("1.登录2.退出");
        Scanner scanner = new Scanner(System.in);
        String choice = scanner.nextLine();
        switch (choice) {
            case "1":
                login(scanner);
                do {
                    System.out.println("1.添加2.删除3.修改4.查询5.退出");
                    String secChoice = scanner.nextLine();
                    switch (secChoice) {
                        case "1":
                            addStu(scanner, stus, index);
                            break;
                        case "2":
                            System.out.println("请输入要删除的学生姓名");
                            String name = scanner.nextLine();
                            for (int i = 0; i < index; i++) {
                                if (stus[i][0].equals(name)) {
                                    stus[i] = null;
                                }
                            }
                            break;
                        case "3":
                            System.out.println("请输入要修改的学生姓名");
                            String n = scanner.nextLine();
                            System.out.println("请输入要修改的学生年龄");
                            String age = scanner.nextLine();
                            for (int i = 0; i < index; i++) {
                                if (stus[i][0].equals(n)) {
                                    stus[i][1] = age;
                                }
                            }
                            break;
                        case "4":
                            for (int i = 0; i < index; i++) {
                                for (int j = 0; j < stus[i].length; j++) {
                                    if (stus[i] != null) {
                                        System.out.println(stus[i][j]);
                                    }
                                }
                            }
                            break;
                        case "5":
                            break;
                    }
                } while (true);
            case "2":
                System.out.println("谢谢使用");
                break;
            default:
                System.out.println("无效输入");
        }
    }
}
